<html>
<head>
<title>Employee Sales Result</title>
<style type="text/css">
body {
	font-family:verdana,arial,sans-serif;
	font-size:10pt;
	margin:30px;
	background-color:#ffcc00;
	}
</style>
</head>
<body>
<?php
date_default_timezone_set('UTC');

$username="bsc353_4";
$password="sonbeans";
$database="bsc353_4";

$empID=$_POST['employeeid'];
$branchID=$_POST['branchid'];

if ($empID==""||$branchID=="Select One")
{
    echo"Error. Please select an option for the Branch.";
}

else
{

mysql_connect("clipper.encs.concordia.ca",$username,$password) or die ("Unable to connect to database");

@mysql_select_db($database) or die ("Unable to select database");


// Check connection


if ($branchID=='All Of MBS')
{
    $query="SELECT Employee.employeeID, Employee.name, COUNT(Employee.employeeID) AS totalSales FROM Employee JOIN Sale ON Employee.employeeID = Sale.employeeID WHERE Employee.employeeID = '$empID' GROUP BY Employee.employeeID";
    //echo "$query";
}
else
{   
    $query="SELECT Employee.employeeID, Employee.name, COUNT(Employee.employeeID) AS totalSales FROM Employee JOIN Sale ON Employee.employeeID = Sale.employeeID WHERE Employee.employeeID = '$empID' AND Sale.storeBranchID = '$branchID' GROUP BY Employee.employeeID";
    //echo "$query";
}
$result=mysql_query($query) or die ("failed to find record");
$num=mysql_numrows($result);

//echo "1 record found";
}
?>

<table border="1" cellspacing="2" cellpadding="2">
<tr>
<td><font face="Arial, Helvetica, sans-serif">EmployeeID</font></td>
<td><font face="Arial, Helvetica, sans-serif">Employee Name</font></td>
<td><font face="Arial, Helvetica, sans-serif">Total Sales Number</font></td>
</tr>

<?php
$i=0;
if ($num != 0)
{
    $f3=mysql_result($result,$i,"totalSales");
}
else
{
    $query="SELECT employeeID, Employee.name FROM Employee WHERE employeeID='$empID'";
    $result=mysql_query($query) or die ("failed to find record");
}

    $f1=mysql_result($result,$i,"Employee.employeeID");
    $f2=mysql_result($result,$i,"Employee.name");

?>

<tr>
<td><font face="Arial, Helvetica, sans-serif"><?php echo $f1; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><?php echo $f2; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><?php
    if ($num != 0) echo $f3;
    else echo "0";
?></font></td>
</tr>

<?php
    mysql_close();
?>

</body>
</html>